#!/usr/bin/env node
const inquirer = require("inquirer");
const fs = require("fs");
const path = require("path");
const ejs = require("ejs");
inquirer.prompt([
    {
        type:"input",
        name:"name",
        message:"Project name ?"
    }
]).then((answers)=>{
    console.log(answers);
    //模板目录
    const tmplDir = path.join(__dirname,"templates");
    //目标目录
    const destDir = process.cwd()
    console.log(tmplDir,'tmplDir');
    fs.readdir(tmplDir,(err,files)=>{
        if(err) throw err;

        files.forEach((file)=>{
            ejs.renderFile(path.join(tmplDir,file),answers,(err,result)=>{
                if(err) throw err
                fs.writeFileSync(path.join(destDir,file),result)
            })
        })
     
    //    ejs.renderFile(path.join(tmplDir))
    })
    
})